package demo14;


import java.util.Arrays;
import java.util.Comparator;

public class Test {
    public static void main(String[] args) {
        // 目标：掌握如何对数组中的对象进行排序。
        Student[] students = new Student[4];
        students[0] = new Student("蜘蛛精", 169.5, 23);
        students[1] = new Student("紫霞", 163.8, 26);
        students[2] = new Student("紫霞", 163.8, 26);
        students[3] = new Student("至尊宝", 167.5, 24);
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                if (o1.getAge() <= o2.getAge()) return -1;
                else return 1;
            }
        });
        for (int i = 0; i < students.length; i++) {
            System.out.println(students[i]);
        }
    }
}
